package app.project.directionlensproject.map;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View;
import app.project.directionlensproject.R;
import app.project.directionlensproject.model.Place;

@SuppressLint("DrawAllocation")
public class RotateCameraSurface extends View {
	Paint p;
	ArrayList<Place> arrListPlace;
	private Context mContext;
	private Bitmap b;
	public RotateCameraSurface(Context context) {
		super(context);
		this.mContext=context;
		p = new Paint();
	}

	public RotateCameraSurface(Context context, ArrayList<Place> _listPlace) {
		super(context);
		this.mContext=context;
		this.arrListPlace = _listPlace;
		p = new Paint();
	}

	@SuppressLint("DrawAllocation")
	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		b = BitmapFactory.decodeResource(getResources(),
				R.drawable.ic_launcher);
		p.setColor(Color.RED);
		p.setTextSize(25);

		for (int i = 0; i < arrListPlace.size(); i++) {
			// if(i%100==0){
			canvas.drawBitmap(b, 20, i * 70, p);
			canvas.drawText(arrListPlace.get(i).placename, 120, i * 70, p);
			// }
			// else{
			// canvas.drawBitmap(b, 60, 120 + i, p);
			// canvas.drawText("Text to be drwaw", 160,140+i,p);
			// }
		}
	}

	@Override
	public boolean onTouchEvent(final MotionEvent ev) {
		switch (ev.getAction()) {
		case MotionEvent.ACTION_DOWN: {
			// Code on finger down
			float posX = ev.getX();
			float posY = ev.getY();
			float boundX=b.getWidth();
			float boundY=b.getHeight();
			
			// 80x80 pixel square located 20 pixels left, 20 pixels top.
			float x1 = 20, y1 = 70;
					
			if ((posX >= x1 && posX <= x1+boundX) && (posY >= y1 && posY <= y1+boundY)) {
				// we are in the square
				//Toast.makeText(mContext, "Click in"+"|"+"posX="+posX+"|posY="+posY+"|boundX="+boundX+"|boundY="+boundY, Toast.LENGTH_LONG).show();
			} else {
				// we are somewhere else on the canvas
				//Toast.makeText(mContext, "Click out"+"|"+"posX="+posX+"|posY="+posY+"|boundX="+boundX+"|boundY="+boundY, Toast.LENGTH_LONG).show();
			}

			break;
		}
		case MotionEvent.ACTION_UP: {
			// Code on finger up
			break;
		}
		case MotionEvent.ACTION_MOVE: {
			// Code on finger move
			break;
		}
		}
		return true;
	}
}